#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2021-12-29 16:08
# @Author : huabao.tan
# @File : demo12.py
# @Software: PyCharm

from mysql_db.db import *
from mysql_db.config import *
from jx3_api.api import *



class WriteMysql:

    def __init__(self,name):
        self.db = DB()
        self.p = Price('%s'%name)

    def write(self):

        data = self.p.goods_json
        info = data['data']['info']
        upload = data['data']['upload']
        data=data['data']['data']
        for b in data:
            for a in b:
                sql = """INSERT INTO info_item(item_name, type, server, zone, price, type_sales, time, info, upload) value ('%s','%s','%s','%s','%s','%s','%s','%s','%s');"""%(a['name']
                ,a['type'],self.p.dealStr(a['server']),self.p.dealStr(a['zone']),self.p.dealStr(str(a['price']),0),a['sales'], a['time'],info, upload )
                self.db.execute_sql(sql)
        self.db.commit()
        self.db.close()



def que_info():
    data = input('输入要查询内容：')
    p = WriteMysql('%s'%data)
    p.write()
    print('已经写入到数据库')


que_info()